import 'package:flutter/material.dart';
import 'package:get/get.dart' hide WidgetPaddingX;
import 'package:hotpot/widgets/widget_ext.dart';
import 'package:hotpot/widgets/z_container.dart';

class BaseDialog extends StatelessWidget {
  final WidgetBuilder builder;
  final String? title;
  final GestureTapCallback? onSubmit;
  final double width;
  final double height;

  const BaseDialog({super.key, required this.builder, this.title, this.onSubmit, required this.width, required this.height});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        ZContainer(
          color: Colors.white,
          radius: 20,
          width: width,
          height: height,
          child: Column(
            children: [
              const Icon(Icons.close_outlined)
                  .paddingSymmetric(horizontal: 10, vertical: 3)
                  .gestureDetector(onTap: () => Get.back())
                  .alignRight(),
              if (title != null) title.text(size: 12, bold: true),
              builder(context).expanded(),
              if (onSubmit != null)
                ZContainer(
                  height: 50,
                  radius: 6,
                  color: const Color(0xFFEEF2FE),
                  alignment: Alignment.center,
                  margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 15),
                  child: 'OK'.text(size: 12, bold: true),
                ).gestureDetector(onTap: onSubmit),
            ],
          ),
        ),
      ],
    );
  }
}

showCustomDialog({
  required WidgetBuilder builder,
  String? title,
  double width = 355,
  required double height,
  GestureTapCallback? onSubmit,
}) {
  return showDialog(
    context: Get.context!,
    builder: (_) => BaseDialog(builder: builder, title: title, width: width, height: height, onSubmit: onSubmit),
  );
}
